package com.example.bzh.gamecat.ui.society;

import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.bzh.gamecat.R;
import com.example.bzh.gamecat.bean.ActiveListBean;

import java.util.List;

/**
 * Created by MyPC on 2016/8/15.
 */
public class ActiveListAdapter extends BaseAdapter {
    private List<ActiveListBean> activeListBeen;
    public ActiveListAdapter(List<ActiveListBean> activeListBeen){
        this.activeListBeen = activeListBeen;
    }

    @Override
    public int getCount() {
        return activeListBeen.size();
    }

    @Override
    public Object getItem(int i) {
        return activeListBeen.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(final int position, View view, final ViewGroup viewGroup) {
        ViewHolder holder;
        if (view == null){
            view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.active_item_society,null);
            holder = new ViewHolder(view);
            view.setTag(holder);
        }else {
            holder = (ViewHolder) view.getTag();
        }
        final ActiveListBean activeListBean = activeListBeen.get(position);

        holder.tvContent.setText(activeListBean.getTitle());

        holder.tvContent.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(viewGroup.getContext(),SecondActivity.class);
                intent.putExtra("weburl",activeListBean.getUrl());
                intent.putExtra("title",activeListBean.getTitle());
                viewGroup.getContext().startActivity(intent);
            }
        });

        return view;
    }

    class ViewHolder{
        private TextView tvContent;
        public ViewHolder(View view){
            tvContent = (TextView) view.findViewById(R.id.text_item_active);
        }

    }


}
